package com.zem.imos.Controller;

import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.zem.imos.Entity.*;
import com.zem.imos.Entity.Params.ParamsPatient;
import com.zem.imos.Entity.Params.ParamsRegister;
import com.zem.imos.Service.AdminService;
import com.zem.imos.Service.DoctorService;
import com.zem.imos.Service.DrugsService;
import com.zem.imos.Service.UserService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RestController;

import javax.servlet.http.HttpServletRequest;
import java.util.List;


@RestController
public class UserController {
    @Autowired
    private AdminService adminService;
    @Autowired
    private DrugsService drugsService;
    @Autowired
    private UserService userService;
    @Autowired
    private DoctorService doctorService;

    /**
     * 用户预约挂号
     * @author ZSQ
     * @Time 2021/11/30
     * @Description 通过用户id获取就诊的挂号单 （就诊单）的开药信息和就诊信息
     * 未测试
     * @test 测试报错
     * @res 提供 doctorId(医生的userid) patientId(患者的userid) date period
     */
    @PostMapping("/register")
    public RespEntity register (HttpServletRequest request, ParamsRegister paramsRegister) {
        return userService.register(request, paramsRegister);
    }

    /**
     * 患者获取该患者所有的就诊济记录
     * @author ZEM
     * @Time 2021/11/30
     * @Description 根据患者id获取该患者的所有就诊记录（就诊时间、症状、诊断、给药情况）
     * 未测试
     * @test 是用医生的token查还是患者的token查，需求不明确，用患者token测试，还是精度不够的问题
     */
    @PostMapping("/doctor/getuservisit")
    public RespEntity getuservisitbyuser (HttpServletRequest request, Integer page, Integer limit, Long id) {
        Page respage = new Page(page,limit);
        return userService.getuservisit(request, respage, id);
    }

    /**
     * 患者获取自身信息
     * @author ZEM
     * @Time 2021/11/30
     * @Description 患者获取自身信息
     * 未测试
     * @test 用token解析出来的id为null
     */
    @GetMapping("/getuserinfo")
    public RespEntity getuserinfo (HttpServletRequest request) {
        return userService.getuserinfo(request);
    }

    /**
     * 患者获取医院的部门信息
     * @author ZEM
     * @Time 2021/11/30
     * @Description 验证token的role为患者，获取医院的部门信息
     * 测试
     * @test ZSQ
     */
    @GetMapping("/getdepartment")
    public RespEntity getdepartment (HttpServletRequest request) {
        return userService.getdepartment(request);
    }
}
